package com.wtwd.campus.attendancereceiver;

import com.wtwd.campus.annotation.MsgType;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.AttendanceProduct;
import com.wtwd.campus.entity.MqAttendanceData;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.receiver.IReceiverHandler;
import com.wtwd.campus.service.AttendanceProductService;
import com.wtwd.campus.utils.AttendanceCommandUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@MsgType(value = Constants.IDENTITY)
public class AttendanceIndentityHandler implements IReceiverHandler {
    @Autowired
    private AttendanceProductService attendanceService;
    @Autowired
    private AttendanceCommandUtils attendanceCommandUtils;

    @Override
    public void handlerMessage(MqMessage mqMessage) {
        MqAttendanceData mqAttendanceData = (MqAttendanceData) mqMessage.getObject();
        String productNo = mqAttendanceData.getProductNo();
        //首先判断考勤机是否入库
        AttendanceProduct attendance = attendanceService.getAttendanceProductByProNo(productNo);
        if (attendance != null) {
            //给考勤机回复一条时间校准指令
            attendanceCommandUtils.sendTimeAdjusting(productNo);
        }
    }
}
